﻿@using DeliveryPlus.Web.Classes.Ext
@using DeliveryPlus.Web.DAL.Entities
@model dynamic

@{
    ViewBag.Title = "Заказ и доставка еды в Хабаровске, Единая Служба Доставки Еды";
    Layout = "../Shared/Layout.cshtml";
    var news = (IList<Article>) ViewBag.news;
    var popular = (IList<Dishe>) ViewBag.popular;
}

<div id="page-main" class="page">
    @* Популярные блюда *@
    <div id="popular">
        <div id="popular-title">
            <img src="~/Content/images/main/popular-title.png" />
        </div>
        <div id="popular-wrapper">
            @foreach (var dish in popular)
            {
            <div class="popular-dish">
                <div class="popular-dish-image">
                    @if (!String.IsNullOrEmpty(dish.Photo))
                    {
                        <img src="/Files/Dish/@dish.Photo" alt="@dish.Title, @dish.Cafe.Title, Хабаровск"/>
                    }
                </div>
                <div class="popular-desc">
                    <div class="popular-desc-title">
                        <a href="/dish/@dish.Id">@dish.Title</a>
                    </div>
                    <div class="popular-desc-content">
                        @dish.Description
                    </div>
                    <div class="popular-sub-info">
                        Заведение: <span class="info-val">@dish.Cafe.Title</span>
                    </div>
                    <div class="popular-sub-info">
                        № блюда: <span class="info-val">@dish.Energy</span>
                    </div>
                    @if (!String.IsNullOrEmpty(dish.Weight))
                    {
                    <div class="popular-sub-info">
                        Порция: <span class="info-val">@dish.Weight грамм</span>
                    </div>
                    }
                    <div class="popular-price">
                        Цена: <span class="val">@String.Format("{0:c}",dish.Price)</span> <span class="popular-order" title="В корзину" onclick="orderDish(@dish.Id)"></span>
                    </div>
                </div>
            </div>
            }
            
        </div>
        <ul id="popular-switcher">
            <li data-id="1" class="active"></li>
            <li data-id="2"></li>
            <li data-id="3"></li>
            <li data-id="4"></li>
            <li data-id="5"></li>
        </ul>
        <img src="~/Content/images/main/popular-bottom.png" />
    </div>
    @* Новости *@
    <div id="news">
        <div id="news-title">
            <img src="~/Content/images/main/news-title.png" />
        </div>
        <div id="news-wrapper">
            @foreach (var article in news)
            {
                <div class="news-pub">
                    <div class="red news-date">
                        @article.PublicationDate.FormatDate() г.
                    </div>
                    <div class="news-title">
                        <a href="/article/@article.Id">@article.Title</a>
                    </div>
                </div>
            }
        </div>
        <div id="all-news" onclick="window.location.href='/articles';">
            
        </div>
        <img src="~/Content/images/main/news-bottom.png" />
    </div>
</div>
<script type="text/javascript">
    $(".popular-dish").first().show();
    $("#popular-switcher li").click(function() {
        var idx = $(this).index();
        $("#popular-switcher li").removeClass("active");
        $(this).addClass("active");
        var populars = $(".popular-dish");
        populars.fadeOut("slow");
        populars.eq(idx).stop(true, true).fadeIn("slow");
    });

    setInterval(function() {
        var current = $("#popular-switcher .active");
        var next = $(current).index() == 4 ? $("#popular-switcher li").first() : $(current).next();
        $(next).click();
    }, 5000);
</script>
